<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta name="generator" content="Hugo 0.82.1" />
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Go 开发规范#命名规范# 命名不要使用 underscroses 使用 camelStype 或者 PascalStyle     Item Style Sample      file camel owner    testing file lower_test.go owner_test.go    field camel owner    getter Pascal Owner() need not key SetXXX   setter Pascal SetOwner()    interface Pascal Reader one-method interface name is the method name &#43; er   string converter Pascal String() do not use ToString    注释#  块注释 /* block comment */">
<meta name="theme-color" content="#FFFFFF"><meta property="og:title" content="Go 开发规范" />
<meta property="og:description" content="Go 开发规范#命名规范# 命名不要使用 underscroses 使用 camelStype 或者 PascalStyle     Item Style Sample      file camel owner    testing file lower_test.go owner_test.go    field camel owner    getter Pascal Owner() need not key SetXXX   setter Pascal SetOwner()    interface Pascal Reader one-method interface name is the method name &#43; er   string converter Pascal String() do not use ToString    注释#  块注释 /* block comment */" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://example.org/docs/guidelines/" /><meta property="article:section" content="docs" />



<title>Go 开发规范 | My Golang Book</title>
<link rel="manifest" href="/manifest.json">
<link rel="icon" href="/favicon.png" type="image/x-icon">
<link rel="stylesheet" href="/book.min.2bc2364a4a4b31f0ec1debecf0a8f90a840821f143dfe1ac6a0f7cbcbdcf64ac.css" integrity="sha256-K8I2SkpLMfDsHevs8Kj5CoQIIfFD3&#43;Gsag98vL3PZKw=">
<script defer src="/en.search.min.84ce9693e6c02d95376f29aeb794c11824d09ed0440f910f008e91e9ed0436e4.js" integrity="sha256-hM6Wk&#43;bALZU3bymut5TBGCTQntBED5EPAI6R6e0ENuQ="></script>
<!--
Made with Book Theme
https://github.com/alex-shpak/hugo-book
-->

  
</head>

<body dir="ltr">
  <input type="checkbox" class="hidden toggle" id="menu-control" />
  <input type="checkbox" class="hidden toggle" id="toc-control" />
  <main class="container flex">
    <aside class="book-menu">
      <div class="book-menu-content">
        
  <nav>
<h2 class="book-brand">
  <a href="/"><span>My Golang Book</span>
  </a>
</h2>


<div class="book-search">
  <input type="text" id="book-search-input" placeholder="Search" aria-label="Search" maxlength="64" data-hotkeys="s/" />
  <div class="book-search-spinner hidden"></div>
  <ul id="book-search-results"></ul>
</div>











  



  
  <ul>
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/introduction/" class="">Golang 介绍</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/installation/" class="">安装、准备开发环境</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/go-routine/" class="">并发处理 - Go 协程</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/workspace-module/" class="">管理Go模块</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/erro-handling/" class="">错误处理</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/resources/" class="">Golang 资源</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/statements/" class="">Go For语句</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/guidelines/" class=" active">Go 开发规范</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/logging/" class="">日志</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/data-init/" class="">Data Init</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/data-types/" class="">Data Types</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/debug/" class="">Debug</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/dynamic-programing/" class="">Dynamic Programing</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/ecosystem/" class="">Ecosystem</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/performance/" class="">Performance</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/struct-interface/" class="">Struct Interface</a>
  

        </li>
      
    
      
        <li>
          
  
  

  
    <a href="http://example.org/docs/struct-tags/" class="">Struct Tags</a>
  

        </li>
      
    
  </ul>















</nav>




  <script>(function(){var a=document.querySelector("aside.book-menu nav");addEventListener("beforeunload",function(b){localStorage.setItem("menu.scrollTop",a.scrollTop)}),a.scrollTop=localStorage.getItem("menu.scrollTop")})()</script>


 
      </div>
    </aside>

    <div class="book-page">
      <header class="book-header">
        
  <div class="flex align-center justify-between">
  <label for="menu-control">
    <img src="/svg/menu.svg" class="book-icon" alt="Menu" />
  </label>

  <strong>Go 开发规范</strong>

  <label for="toc-control">
    
    <img src="/svg/toc.svg" class="book-icon" alt="Table of Contents" />
    
  </label>
</div>


  
  <aside class="hidden clearfix">
    
  
<nav id="TableOfContents">
  <ul>
    <li><a href="#命名规范">命名规范</a></li>
    <li><a href="#注释">注释</a></li>
  </ul>
</nav>



  </aside>
  
 
      </header>

      
      
  <article class="markdown"><h1 id="go-开发规范">
  Go 开发规范
  <a class="anchor" href="#go-%e5%bc%80%e5%8f%91%e8%a7%84%e8%8c%83">#</a>
</h1>
<h2 id="命名规范">
  命名规范
  <a class="anchor" href="#%e5%91%bd%e5%90%8d%e8%a7%84%e8%8c%83">#</a>
</h2>
<ul>
<li>命名不要使用 underscroses</li>
<li>使用 camelStype 或者 PascalStyle</li>
</ul>
<table>
<thead>
<tr>
<th>Item</th>
<th>Style</th>
<th>Sample</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>file</td>
<td>camel</td>
<td>owner</td>
<td></td>
</tr>
<tr>
<td>testing file</td>
<td>lower_test.go</td>
<td>owner_test.go</td>
<td></td>
</tr>
<tr>
<td>field</td>
<td>camel</td>
<td>owner</td>
<td></td>
</tr>
<tr>
<td>getter</td>
<td>Pascal</td>
<td>Owner()</td>
<td>need not key SetXXX</td>
</tr>
<tr>
<td>setter</td>
<td>Pascal</td>
<td>SetOwner()</td>
<td></td>
</tr>
<tr>
<td>interface</td>
<td>Pascal</td>
<td>Reader</td>
<td>one-method interface name is <code>the method name</code> + <code>er</code></td>
</tr>
<tr>
<td>string converter</td>
<td>Pascal</td>
<td>String()</td>
<td>do not use <code>ToString</code></td>
</tr>
</tbody>
</table>
<h2 id="注释">
  注释
  <a class="anchor" href="#%e6%b3%a8%e9%87%8a">#</a>
</h2>
<ul>
<li>
<p>块注释
<code>/* block comment */</code></p>
</li>
<li>
<p>行注释
<code>// line comment</code></p>
</li>
<li>
<p>包注释(package comment)
一个包需要一个包注释。
如果一个包包含多个文件，只需要在一个文件里加上包注释即可。</p>
</li>
</ul>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#75715e">/*
</span><span style="color:#75715e">  The package is a sample
</span><span style="color:#75715e"> */</span>
 <span style="color:#f92672">package</span> <span style="color:#a6e22e">sample</span>
</code></pre></div></article>
 
      

      <footer class="book-footer">
        
  <div class="flex flex-wrap justify-between">





</div>

 
        
      </footer>

      
  
  <div class="book-comments">

</div>
  
 

      <label for="menu-control" class="hidden book-menu-overlay"></label>
    </div>

    
    <aside class="book-toc">
      <div class="book-toc-content">
        
  
<nav id="TableOfContents">
  <ul>
    <li><a href="#命名规范">命名规范</a></li>
    <li><a href="#注释">注释</a></li>
  </ul>
</nav>


 
      </div>
    </aside>
    
  </main>

  
</body>

</html>












